<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Dagger2,依赖注入," />










<meta name="description" content="dagger2是一个依赖注入框架，可以用于功能模块的解耦，非常适合于和MVP搭配使用，下面就来介绍一下dagger2一些使用方式">
<meta name="keywords" content="Dagger2,依赖注入">
<meta property="og:type" content="article">
<meta property="og:title" content="Dagger2使用">
<meta property="og:url" content="http://yoursite.com/2017/03/16/Dagger2使用/index.html">
<meta property="og:site_name" content="SISYPHUSER">
<meta property="og:description" content="dagger2是一个依赖注入框架，可以用于功能模块的解耦，非常适合于和MVP搭配使用，下面就来介绍一下dagger2一些使用方式">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://raw.githubusercontent.com/codepath/android_guides/master/images/dagger_dependency.png">
<meta property="og:image" content="https://raw.githubusercontent.com/codepath/android_guides/master/images/dagger_subcomponent.png">
<meta property="og:image" content="https://raw.githubusercontent.com/codepath/android_guides/master/images/subcomponent_builders.png">
<meta property="og:image" content="http://7xtcmn.com1.z0.glb.clouddn.com/subcomponent_1.png">
<meta property="og:image" content="http://7xtcmn.com1.z0.glb.clouddn.com/subcomponent_2.png">
<meta property="og:image" content="http://7xtcmn.com1.z0.glb.clouddn.com/subcomponent_3.png">
<meta property="og:updated_time" content="2018-03-03T05:13:46.819Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Dagger2使用">
<meta name="twitter:description" content="dagger2是一个依赖注入框架，可以用于功能模块的解耦，非常适合于和MVP搭配使用，下面就来介绍一下dagger2一些使用方式">
<meta name="twitter:image" content="https://raw.githubusercontent.com/codepath/android_guides/master/images/dagger_dependency.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/03/16/Dagger2使用/"/>





  <title>Dagger2使用 | SISYPHUSER</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">SISYPHUSER</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-word">
          <a href="/word/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-calendar"></i> <br />
            
            word
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/03/16/Dagger2使用/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Andy">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SISYPHUSER">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Dagger2使用</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-03-16T15:34:40+08:00">
                2017-03-16
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Android/" itemprop="url" rel="index">
                    <span itemprop="name">Android</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>dagger2是一个依赖注入框架，可以用于功能模块的解耦，非常适合于和MVP搭配使用，下面就来介绍一下dagger2一些使用方式</p>
<a id="more"></a>
<p><strong>导入项目库</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">dependencies &#123;</span><br><span class="line">    classpath &apos;com.neenbedankt.gradle.plugins:android-apt:1.8&apos;</span><br><span class="line">&#125;</span><br><span class="line">apply plugin: &apos;com.neenbedankt.android-apt&apos;</span><br><span class="line">dependencies &#123;</span><br><span class="line">    compile &apos;com.google.dagger:dagger:2.4&apos;</span><br><span class="line">    apt &apos;com.google.dagger:dagger-compiler:2.4&apos;</span><br><span class="line">    compile &apos;org.glassfish:javax.annotation:10.0-b28&apos;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>先来看一个简单的例子：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">public class MainActivity extends AppCompatActivity &#123;</span><br><span class="line">    @Inject</span><br><span class="line">    B b;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在一个Activity中我需要一个B的实例，通常情况下我们直接b=new B();这样来初始化，但是使用了Dagger2之后就只需要添加一个@Inject注解就可以了。<br>难道这样就可以了吗？<br>不不不，我们还需要做一些配置</p>
<ol>
<li>创建我们的测试类B</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">public class B &#123;</span><br><span class="line">    C c;</span><br><span class="line"></span><br><span class="line">    @Inject</span><br><span class="line">    public B(C c) &#123;</span><br><span class="line">        this.c = c;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String geti() &#123;</span><br><span class="line">        return &quot;result&quot;;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>等等，这里只有一个构造方法，并且要传入C类，这个C类又是什么。<br>我们一步步来，可以看到在构造方法上有一个@Inject，这个注解和MainActivity中的注解名称一样但是功能是不同的。在MainActivity中放在成员变量上面，是告诉dagger2我需要一个B的实例。在B中放在构造函数上面，是告诉dagger2可以用这个构造函数来创建B的实例。<br>接下来就需要一个中间类来连接MainActivity和B，提供B的初始化条件C</p>
<ol>
<li>创建MyComponent</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"> @Component(modules = MyModule.class)</span><br><span class="line">public interface MyComponent &#123;</span><br><span class="line">    void inject(MainActivity a);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>这里用到了@Component注解，告诉dagger2需要用到哪些Module</p>
<ol>
<li>创建MyModule</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">public class MyModule &#123;</span><br><span class="line">    @Provides</span><br><span class="line">    public C provideB()&#123;</span><br><span class="line">        return new C();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>提供了C类的实例</p>
<ol>
<li>在MainActivity中初始化 </li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DaggerMyComponent.builder().myModule(new MyModule()).build().inject(this);</span><br></pre></td></tr></table></figure>
<p>DaggerMyComponent如果没有找到，可以build一下项目，这是一个由dagger2创建的实现了MyComponent的类</p>
<p>简单说先dagger2找到类的实例的基本步骤<br><em>1. 查找Module中是否存在创建该类的方法。</em><br><em>2. 若存在创建类方法，查看该方法是否存在参数</em><br><em>2.1 若存在参数，则按从步骤1开始依次初始化每个参数</em><br><em>2.2 若不存在参数，则直接初始化该类实例，一次依赖注入到此结束</em><br><em>3. 若不存在创建类方法，则查找Inject注解的构造函数，看构造函数是否存在参数</em><br><em>3.1 若存在参数，则从步骤1开始依次初始化每个参数</em><br><em>3.2 若不存在参数，则直接初始化该类实例，一次依赖注入到此结束</em></p>
<p><strong>Qualifier(限定符)解决依赖注入迷失</strong><br>什么是依赖迷失？</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">public class B &#123;</span><br><span class="line">    C c;</span><br><span class="line"></span><br><span class="line">	@Inject</span><br><span class="line">    public B() &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Inject</span><br><span class="line">    public B(C c) &#123;</span><br><span class="line">        this.c = c;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String geti() &#123;</span><br><span class="line">        return &quot;result&quot;;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>想上面的这种写法，当一个类中有两个或两个以上的构造方法时，dagger2就不知道用哪个构造方法来创建对象，这事就依赖迷失。当出现依赖迷失时项目编译时就会报错。<br>Qualifier这时就可以发挥他的作用了，关于Qualifier有两种基本的用法</p>
<ol>
<li>使用@Named注解<br>在Module中</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">@Provides</span><br><span class="line">@Named(&quot;c&quot;)</span><br><span class="line">public B provideB1(C c)&#123;</span><br><span class="line">    return new B(c);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@Provides</span><br><span class="line">@Named(&quot;qualifier&quot;)</span><br><span class="line">public B provideB2(C c)&#123;</span><br><span class="line">    return new B();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在MainActivity中</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">@Inject</span><br><span class="line">@Named(&quot;qualifier&quot;)</span><br><span class="line">B b;</span><br></pre></td></tr></table></figure>
<ol>
<li>自定义Qualifier注解<br>创建注解</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">@Qualifier</span><br><span class="line">@Documented</span><br><span class="line">@Retention(RUNTIME)</span><br><span class="line">public @interface HasC &#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在Module中使用</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">@Provides</span><br><span class="line">@HasC</span><br><span class="line">public B provideB1(C c)&#123;</span><br><span class="line">    return new B(c);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@Provides</span><br><span class="line">@NoC</span><br><span class="line">public B provideB2()&#123;</span><br><span class="line">    return new B();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在MainActivity中使用</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">@Inject</span><br><span class="line">@HasC</span><br><span class="line">B b;</span><br></pre></td></tr></table></figure>
<p><strong>Component组织方式</strong></p>
<ul>
<li>依赖方式<br><img src="https://raw.githubusercontent.com/codepath/android_guides/master/images/dagger_dependency.png" alt="pic1"><br>如上图中E的创建需要依赖C,F两个条件</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">@Singleton</span><br><span class="line">@Component(modules = CModule.class)</span><br><span class="line">public interface AppComponent &#123;</span><br><span class="line">    C c();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@Module</span><br><span class="line">public class CModule &#123;</span><br><span class="line">    @Provides</span><br><span class="line">    public C getc()&#123;</span><br><span class="line">        return new C();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@UserScope</span><br><span class="line">@Component(dependencies = AppComponent.class,modules = BModule.class)</span><br><span class="line">public interface MainComponent &#123;</span><br><span class="line">    void infect(MainActivity a);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@Module</span><br><span class="line">public class BModule &#123;</span><br><span class="line"></span><br><span class="line">    @Provides</span><br><span class="line">    @UserScope</span><br><span class="line">    public B getb(C c)&#123;</span><br><span class="line">        return new B(c);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在上述案例中MainComponent中的B创建需要依赖与AppComponent中的CModule，所以在MainComponent中添加AppComponent依赖dependencies = AppComponent.class，并在AppComponent中将C暴露出来</p>
<p>初始化，一般将AppComponent的初始化放在Application中<br>build = DaggerAppComponent.builder().cModule(new CModule()).build();</p>
<p><em>MainActivity中的初始化</em></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">DaggerMainComponent.builder()</span><br><span class="line">	.appComponent(App.build)</span><br><span class="line">	.bModule(new BModule())</span><br><span class="line">	.build()</span><br><span class="line">	.infect(this);</span><br></pre></td></tr></table></figure>
<p><em>自定义的Scope</em></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">@Scope</span><br><span class="line">@Retention(RUNTIME)</span><br><span class="line">public @interface UserScope &#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>包含方式<br><img src="https://raw.githubusercontent.com/codepath/android_guides/master/images/dagger_subcomponent.png" alt="pic2"></li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">@UserScope</span><br><span class="line">@Subcomponent(modules = BModule.class)</span><br><span class="line">public interface MainComponent &#123;</span><br><span class="line">    void infect(MainActivity a);</span><br><span class="line">&#125;</span><br><span class="line">@Singleton</span><br><span class="line">@Component(modules = CModule.class)</span><br><span class="line">public interface AppComponent &#123;</span><br><span class="line">    MainComponent m(BModule b);</span><br><span class="line">&#125;</span><br><span class="line">DaggerAppComponent.builder()</span><br><span class="line">	.cModule(new CModule())</span><br><span class="line">	.build()</span><br><span class="line">	.m(new BModule())</span><br><span class="line">	.infect(this);</span><br></pre></td></tr></table></figure>
<ul>
<li>继承方式<br><img src="https://raw.githubusercontent.com/codepath/android_guides/master/images/subcomponent_builders.png" alt="pic2"><br>这种方式比较复杂，需要Dagger2版本在2.7及以上，我在实现过程中总是出现一些奇怪的问题，在这里我只把Dependency Injection with Dagger 2中的代码贴上，等过段时间再回来研究<br><img src="http://7xtcmn.com1.z0.glb.clouddn.com/subcomponent_1.png" alt="1"><br><img src="http://7xtcmn.com1.z0.glb.clouddn.com/subcomponent_2.png" alt="2"><br><img src="http://7xtcmn.com1.z0.glb.clouddn.com/subcomponent_3.png" alt="3"></li>
</ul>
<p><strong>参考博客：</strong><br><a href="https://guides.codepath.com/android/Dependency-Injection-with-Dagger-2#proguard" target="_blank" rel="noopener">Dependency Injection with Dagger 2</a><br><a href="http://www.cnblogs.com/all88/p/5788556.html" target="_blank" rel="noopener">浅析Dagger2的使用</a><br><a href="http://www.2cto.com/kf/201604/499397.html" target="_blank" rel="noopener">关于依赖注入框架dagger2的使用和理解</a><br><a href="http://www.jianshu.com/p/cd2c1c9f68d4" target="_blank" rel="noopener">Android：dagger2让你爱不释手-基础依赖注入框架篇</a><br><a href="http://www.jianshu.com/p/1d42d2e6f4a5" target="_blank" rel="noopener">Android：dagger2让你爱不释手-重点概念讲解、融合篇</a><br><a href="http://www.jianshu.com/p/65737ac39c44" target="_blank" rel="noopener">Android：dagger2让你爱不释手-终结篇</a></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Dagger2/" rel="tag"># Dagger2</a>
          
            <a href="/tags/依赖注入/" rel="tag"># 依赖注入</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/03/13/日夜模式切换/" rel="next" title="日/夜模式切换">
                <i class="fa fa-chevron-left"></i> 日/夜模式切换
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/12/07/Android Studio自定义模板/" rel="prev" title="Android Studio自定义模板">
                Android Studio自定义模板 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.gif"
                alt="Andy" />
            
              <p class="site-author-name" itemprop="name">Andy</p>
              <p class="site-description motion-element" itemprop="description">Something Wrong</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">18</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">28</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Andy</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
